|
ARD2
1.00 for Rev B. Hardware
Airbag Reference Demonstrator using MPC5604P
|
00001 00017 #ifndef _LIN_UART_H 00018 #define _LIN_UART_H 00019 #include "derivative.h" 00020 /* 00021 ************************************************************** 00022 * Defines, Macros and Typedefs 00023 **************************************************************/ 00024 /*** Constant Macros ***/ 00025 /* Default Yes and No defines */ 00026 #ifndef TRUE 00027 #define TRUE (1u) 00028 #endif 00029 #ifndef CLEAR 00030 #define CLEAR (0u) 00031 #endif 00032 #ifndef BITS_IN_NIBBLE 00033 #define BITS_IN_NIBBLE (4u) 00034 #endif 00035 #ifndef BITS_IN_BYTE 00036 #define BITS_IN_BYTE (8u) 00037 #endif 00038 #ifndef BITS_IN_32 00039 #define BITS_IN_32 (32u) 00040 #endif 00041 #ifndef BITS_IN_16 00042 #define BITS_IN_16 (16u) 00043 #endif 00044 #ifndef BYTES_IN_32 00045 #define BYTES_IN_32 (4u) 00046 #endif 00047 #ifndef BYTES_IN_16 00048 #define BYTES_IN_16 (2u) 00049 #endif 00050 00051 #ifndef BIT_DEFINITION 00052 #define BIT_DEFINITION 00053 #define BIT0 (1u << 0u) 00054 #define BIT1 (1u << 1u) 00055 #define BIT2 (1u << 2u) 00056 #define BIT3 (1u << 3u) 00057 #define BIT4 (1u << 4u) 00058 #define BIT5 (1u << 5u) 00059 #define BIT6 (1u << 6u) 00060 #define BIT7 (1u << 7u) 00061 #define BIT8 (1u << 8u) 00062 #define BIT9 (1u << 9u) 00063 #define BIT10 (1u << 10) 00064 #define BIT11 (1u << 11) 00065 #define BIT12 (1u << 12) 00066 #define BIT13 (1u << 13) 00067 #define BIT14 (1u << 14) 00068 #define BIT15 (1u << 15) 00069 #define BIT16 (1u << 16) 00070 #define BIT17 (1u << 17) 00071 #define BIT18 (1u << 18) 00072 #define BIT19 (1u << 19) 00073 #define BIT20 (1u << 20) 00074 #define BIT21 (1u << 21) 00075 #define BIT22 (1u << 22) 00076 #define BIT23 (1u << 23) 00077 #define BIT24 (1u << 24) 00078 #define BIT25 (1u << 25) 00079 #define BIT26 (1u << 26) 00080 #define BIT27 (1u << 27) 00081 #define BIT28 (1u << 28) 00082 #define BIT29 (1u << 29) 00083 #define BIT30 (1u << 30) 00084 #define BIT31 (1u << 31) 00085 #endif 00086 00087 #define N_LIN_INSTANCES (2u) 00088 00089 #define UART_PHYSICAL_BUFF_SIZE (4u) 00090 00091 #define SCI_TIME_OUT (0x00040000u) 00092 00093 /* Defines for initializing LIN instances */ 00094 #define LIN_UART_ENABLED (0x80000000u) 00095 #define LIN_UART_DISABLED (0x00000000u) 00096 #define LIN_TX_BUFF_1_BYTES (0x00000000u) 00097 #define LIN_TX_BUFF_2_BYTES (0x20000000u) 00098 #define LIN_TX_BUFF_3_BYTES (0x40000000u) 00099 #define LIN_TX_BUFF_4_BYTES (0x60000000u) 00100 #define LIN_RX_BUFF_1_BYTES (0x00000000u) 00101 #define LIN_RX_BUFF_2_BYTES (0x08000000u) 00102 #define LIN_RX_BUFF_3_BYTES (0x10000000u) 00103 #define LIN_RX_BUFF_4_BYTES (0x18000000u) 00104 #define LIN_NO_PARITY_CHECK (0x00000000u) 00105 #define LIN_ODD_PARITY_CHECK (0x06000000u) 00106 #define LIN_EVEN_PARITY_CHECK (0x02000000u) 00107 #define LIN_7_BIT_WORD_SIZE (0x00000000u) 00108 #define LIN_8_BIT_WORD_SIZE (0x01000000u) 00109 00110 /* UART errors */ 00111 #define UART_NO_DATA_RX ((uint8_t)BIT7) 00112 #define UART_INVALID_BUFFER_SIZE ((uint8_t)BIT2) 00113 #define UART_TIMEOUT ((uint8_t)BIT1) 00114 #define UART_NOT_READY ((uint8_t)BIT0) 00115 00116 /*** Function Macros ***/ 00117 #define LIN_MANTISSA(xx) (xx << 8u) 00118 #define LIN_FRACTION(xx) (xx << 20u) 00119 00120 /*** Enums ***/ 00121 enum LIN_STATE_MACHINE_STATES 00122 { 00123 LIN_ASLEEP = 0, LIN_INIT, LIN_IDLE, LIN_BREAK, LIN_BREAK_DELIMITER, 00124 LIN_SYNCH_FIELD, LIN_ID_FIELD, LIN_HEADER_DONE, LIN_DATA_TX_RX, LIN_CHECKSUM 00125 }; 00126 enum LIN_INSTANCES_LIST 00127 { 00128 LIN_INSTANCE_0 = 0, LIN_INSTANCE_1, LIN_INSTANCE_2, LIN_INSTANCE_3 00129 }; 00130 enum LIN_UART_BUFFER_REGISTERS 00131 { 00132 UART_BUFF0 = 0u, UART_BUFF1, UART_BUFF2, UART_BUFF3 00133 }; 00134 00135 /*** TypeDefs ***/ 00136 typedef volatile struct LINFLEX_tag* LINFLEX_t; 00137 00138 typedef union 00139 { 00140 struct 00141 { 00142 vuint32_t Enable: 1; 00143 vuint32_t TxBufferSize: 2; 00144 vuint32_t RxBufferSize: 2; 00145 vuint32_t OddParityEn: 1; 00146 vuint32_t ParityCheckEn: 1; 00147 vuint32_t WordSizeIs8Bits: 1; 00148 vuint32_t BaudRateFraction: 4; 00149 vuint32_t BaudRateMantissa: 12; 00150 vuint32_t Reserved: 6; 00151 vuint32_t Instance: 2; 00152 }P; 00153 vuint32_t W; 00154 } LINUARTConfig_t; 00155 /* 00156 ************************************************************** 00157 * Declarations 00158 **************************************************************/ 00159 /*** Constants ***/ 00160 /*** Globals ***/ 00161 extern vuint8_t gau8LINUARTWordsTx[N_LIN_INSTANCES]; 00162 extern vuint8_t gau8LINUARTWordsRx[N_LIN_INSTANCES]; 00163 extern vuint8_t gau8LINUARTRxFlagHasBeenClearedByTx[N_LIN_INSTANCES]; 00164 /* Globals for 8-bit transfers */ 00165 extern vuint8_t* gpu8LINUARTTxBuffer[N_LIN_INSTANCES]; 00166 extern vuint8_t* gpu8LINUARTRxBuffer[N_LIN_INSTANCES]; 00167 /*** Static Globals ***/ 00168 /* 00169 ************************************************************** 00170 * Function Prototypes 00171 **************************************************************/ 00172 /* 00173 ****************************************************************************** 00174 * 00175 * Function: u8fnUARTWrite() 00176 * 00177 */ 00194 uint8_t u8fnUARTWrite(const uint8_t u8Instance, const uint8_t* pu8UARTTx, 00195 const uint8_t u8Size); 00196 /* 00197 ****************************************************************************** 00198 * 00199 * Function: u8fnUARTRead() 00200 * 00201 */ 00216 uint8_t u8fnUARTRead(const uint8_t u8Instance, const uint8_t* pu8UARTRx, 00217 const uint8_t u8Size); 00218 /* 00219 ****************************************************************************** 00220 * 00221 * Function: u8fnLINUARTSend() 00222 * 00223 */ 00238 uint8_t u8fnLINUARTSend(const uint8_t u8Instance, const uint8_t* pu8UARTTx, \ 00239 const uint8_t u8Size); 00240 /* 00241 ****************************************************************************** 00242 * 00243 * Function: u8fnLINUARTReceive() 00244 * 00245 */ 00259 uint8_t u8fnLINUARTReceive(const uint8_t u8Instance, const uint8_t* pu8UARTRx, 00260 const uint8_t u8IsrEn); 00261 /* 00262 ****************************************************************************** 00263 * 00264 * Function: u8fnConfigLINUARTGeneral() 00265 * 00266 */ 00276 uint8_t u8fnConfigLINUARTGeneral(const LINUARTConfig_t* tLINUARTConfig); 00277 /* 00278 ****************************************************************************** 00279 * 00280 * Function: u8fnLINUARTSetTxData() 00281 * 00282 */ 00296 static uint8_t u8fnLINUARTSetTxData(uint8_t u8Instance); 00297 /* 00298 ****************************************************************************** 00299 * 00300 * Function: u8fnLINUARTGetDataNoIsr() 00301 * 00302 */ 00312 uint8_t u8fnLINUARTGetDataNoIsr(uint8_t u8Instance); 00313 /* 00314 ****************************************************************************** 00315 * 00316 * Function: u8fnLINUARTGetRxData() 00317 * 00318 */ 00330 static uint8_t u8fnLINUARTGetRxData(uint8_t u8Instance); 00331 /* 00332 ****************************************************************************** 00333 * 00334 * Function: u8fnLINWriteTxBuffer() 00335 * 00336 */ 00347 static uint8_t u8fnLINWriteTxBuffer(const uint8_t u8Instance, 00348 const uint8_t u8UARTBufferSize); 00349 /* 00350 ****************************************************************************** 00351 * 00352 * Function: u8fnWaitForUARTTxBufferToEmpty() 00353 * 00354 */ 00366 uint8_t u8fnWaitForUARTTxBufferToEmpty(uint8_t u8Instance, uint32_t u32TimeOut); 00367 /* 00368 ****************************************************************************** 00369 * 00370 * Function: u8fnReturnLINSMMode() 00371 * 00372 */ 00383 static uint8_t u8fnReturnLINSMMode(const uint8_t u8Instance); 00384 /* 00385 ****************************************************************************** 00386 * 00387 * Function: u8fnChangeSMModeLINUART() 00388 * 00389 */ 00401 static uint8_t u8fnChangeSMModeLINUART(const uint8_t u8Instance, 00402 const uint8_t u8Mode); 00403 /* 00404 ****************************************************************************** 00405 * 00406 * Function: u8fnReturnLINTxISRStatus() 00407 * 00408 */ 00422 static uint8_t u8fnReturnLINTxISRStatus(const uint8_t u8Instance); 00423 /* 00424 ****************************************************************************** 00425 * 00426 * Function: u8fnReturnLINRxISRStatus() 00427 * 00428 */ 00440 static uint8_t u8fnReturnLINRxISRStatus(const uint8_t u8Instance); 00441 /* 00442 ****************************************************************************** 00443 * 00444 * Function: vfnEnableLINRxISR() 00445 * 00446 */ 00455 void vfnEnableLINRxISR(uint8_t u8Instance, uint8_t u8Switch); 00456 /* 00457 ****************************************************************************** 00458 * 00459 * Function: vfnEnableLINTxISR() 00460 * 00461 */ 00470 void vfnEnableLINTxISR(uint8_t u8Instance, uint8_t u8Switch); 00471 /* 00472 ****************************************************************************** 00473 * 00474 * Function: vfnGenericLINTxIsr() 00475 * 00476 */ 00484 static void vfnGenericLINTxIsr(uint8_t u8Instance); 00485 /* 00486 ****************************************************************************** 00487 * 00488 * Function: vfnLIN0TxIsr() 00489 * 00490 */ 00498 void vfnLIN0TxIsr(void); 00499 /* 00500 ****************************************************************************** 00501 * 00502 * Function: vfnLIN1TxIsr() 00503 * 00504 */ 00512 void vfnLIN1TxIsr(void); 00513 /* 00514 ****************************************************************************** 00515 * 00516 * Function: vfnLIN2TxIsr() 00517 * 00518 */ 00526 void vfnLIN2TxIsr(void); 00527 /* 00528 ****************************************************************************** 00529 * 00530 * Function: vfnLIN3TxIsr() 00531 * 00532 */ 00540 void vfnLIN3TxIsr(void); 00541 /* 00542 ****************************************************************************** 00543 * 00544 * Function: vfnGenericLINRxIsr() 00545 * 00546 */ 00554 static void vfnGenericLINRxIsr(uint8_t u8Instance); 00555 /* 00556 ****************************************************************************** 00557 * 00558 * Function: vfnLIN0RxIsr() 00559 * 00560 */ 00568 void vfnLIN0RxIsr(void); 00569 /* 00570 ****************************************************************************** 00571 * 00572 * Function: vfnLIN1RxIsr() 00573 * 00574 */ 00582 void vfnLIN1RxIsr(void); 00583 /* 00584 ****************************************************************************** 00585 * 00586 * Function: vfnLIN2RxIsr() 00587 * 00588 */ 00596 void vfnLIN2RxIsr(void); 00597 /* 00598 ****************************************************************************** 00599 * 00600 * Function: vfnLIN3RxIsr() 00601 * 00602 */ 00610 void vfnLIN3RxIsr(void); 00611 #endif /* _FILENAME_H */